import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
  // 创建用户数据
  await prisma.user.createMany({
    data: [
      {
        username: 'duolamon',
        password: '123456',
        nickName: '多啦A梦',
        avatar:
          'https://hsm-image-bucket.oss-cn-guangzhou.aliyuncs.com/chatroom/duolamon2.jpg',
        email: 'duolamon@qq.com',
      },
      {
        username: 'daxion',
        password: '123456',
        nickName: '大熊',
        avatar:
          'https://hsm-image-bucket.oss-cn-guangzhou.aliyuncs.com/chatroom/daxion2.jpg',
        email: 'duolamon@qq.com',
      },
      {
        username: 'jingxiang',
        password: '123456',
        nickName: '静香',
        avatar:
          'https://hsm-image-bucket.oss-cn-guangzhou.aliyuncs.com/chatroom/jingxiang2.jpg',
        email: 'jingxiang@qq.com',
      },
      {
        username: 'xiaofu',
        password: '123456',
        nickName: '小夫',
        avatar:
          'https://hsm-image-bucket.oss-cn-guangzhou.aliyuncs.com/chatroom/xiaofu2.jpg',
        email: 'xiaofu@qq.com',
      },
      {
        username: 'panghu',
        password: '123456',
        nickName: '胖虎',
        avatar:
          'https://hsm-image-bucket.oss-cn-guangzhou.aliyuncs.com/chatroom/panghu2.jpg',
        email: 'panghu@qq.com',
      },
      {
        username: 'xiaohong',
        password: '123456',
        nickName: '小红',
        email: 'duolamon@qq.com',
      },
      {
        username: 'xiaoming',
        password: '123456',
        nickName: '小明',
        email: 'duolamon@qq.com',
      },
      {
        username: 'xiaohua',
        password: '123456',
        nickName: '小花',
        email: 'duolamon@qq.com',
      },
    ],
  });
  // 建立好友数据
  await prisma.friendShip.createMany({
    data: [
      {
        userId: 1,
        friendId: 2,
      },
      {
        userId: 1,
        friendId: 3,
      },
      //   {
      //     userId: 1,
      //     friendId: 4,
      //   },
      //   {
      //     userId: 1,
      //     friendId: 5,
      //   },
      {
        userId: 2,
        friendId: 3,
      },
      {
        userId: 2,
        friendId: 4,
      },
      {
        userId: 2,
        friendId: 5,
      },
      {
        userId: 3,
        friendId: 4,
      },
      {
        userId: 3,
        friendId: 5,
      },
      {
        userId: 4,
        friendId: 5,
      },
    ],
  });

  // 建立好友请求
  await prisma.friendRequest.createMany({
    data: [
      {
        fromUserId: 1,
        toUserId: 4,
        reason: '你好小夫，我是多啦A梦，我想加你为好友',
      },
      {
        fromUserId: 5,
        toUserId: 1,
        reason: '你好多啦A梦，我是胖虎，我想加你为好友',
      },
    ],
  });

  // 创建房间数据
  await prisma.room.createMany({
    data: [
      {
        chatType: 'Group',
        name: '多啦A梦探险队',
      },
      {
        chatType: 'Private',
        name: '单聊1',
      },
      {
        chatType: 'Private',
        name: '单聊2',
      },
      {
        chatType: 'Private',
        name: '单聊3',
      },
      {
        chatType: 'Private',
        name: '单聊4',
      },
    ],
  });

  // 创建用户房间关系数据
  await prisma.userRoom.createMany({
    data: [
      {
        userId: 1,
        roomId: 1,
      },
      {
        userId: 2,
        roomId: 1,
      },
      {
        userId: 3,
        roomId: 1,
      },
      {
        userId: 4,
        roomId: 1,
      },
      {
        userId: 5,
        roomId: 1,
      },
      {
        userId: 1,
        roomId: 2,
      },
      {
        userId: 2,
        roomId: 2,
      },
      {
        userId: 2,
        roomId: 3,
      },
      {
        userId: 3,
        roomId: 3,
      },
      {
        userId: 4,
        roomId: 4,
      },
      {
        userId: 5,
        roomId: 4,
      },
    ],
  });

  // 创建聊天数据
  await prisma.message.createMany({
    data: [
      {
        senderId: 1,
        type: 'Text',
        content: '探险队，出发！',
        roomId: 1,
        createTime: new Date('2024-11-09T01:10:00.000Z'),
      },
      {
        senderId: 2,
        type: 'Text',
        content: '出发！',
        roomId: 1,
        createTime: new Date('2024-11-09T01:10:01.000Z'),
      },
      {
        senderId: 3,
        type: 'Text',
        content: '出发！',
        roomId: 1,
        createTime: new Date('2024-11-09T01:10:02.000Z'),
      },
      {
        senderId: 4,
        type: 'Text',
        content: '出发！',
        roomId: 1,
        createTime: new Date('2024-11-09T01:10:03.000Z'),
      },
      {
        senderId: 5,
        type: 'Text',
        content: '出发！',
        roomId: 1,
        createTime: new Date('2024-11-09T01:10:04.000Z'),
      },
    ],
  });
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
